/*
 * Notes:
 * 1. use SEQUENCE strategy for the id generating, ok or not?
 */
package entity;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author Ye Mei
 */
@Entity(name="Solution")
public class SolutionEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    private String category;
    private String subject;
    private String description;
    private String initialDate;
    private String latestDate;
    
    public SolutionEntity() {
    }

    public void create(String category, String subject, String description) {
        this.category = category;
        this.subject = subject;
        this.description = description;
        this.setInitialDate();
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getInitialDate() {
        return initialDate;
    }

    public void setInitialDate() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.initialDate = dateFormat.format(new Date());
    }

    public String getLatestDate() {
        return latestDate;
    }

    public void setLatestDate() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.latestDate = dateFormat.format(new Date());
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SolutionEntity)) {
            return false;
        }
        SolutionEntity other = (SolutionEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.SolutionEntity[ id=" + id + " ]";
    }
    
}
